with Ada.Text_Io;
use Ada.Text_Io;
with Ada.Integer_Text_Io;
use Ada.Integer_Text_Io;

---------------------------------------------------------
-- Parts paketet. Implementerar de funktioner och      --
-- procedurer som krävs för att hantera Part_Type      --
-- och skapa en lista med parts.                       --
---------------------------------------------------------
package body Parts is

   function Get_Key(Part : in Part_Type) return Integer is
   begin
      return Part.Part_Nr;
   end Get_Key;

   function "<"(Left, Right : in Part_Type) return Boolean is
   begin
      return Left.Part_Nr < Right.Part_Nr;
   end "<";

   function ">"(Left, Right : in Part_Type) return Boolean is
   begin
      return Left.Part_Nr > Right.Part_Nr;
   end ">";

   function "="(Left, Right : in Part_Type) return Boolean is
   begin
      return Left.Part_Nr = Right.Part_Nr;
   end "=";

   procedure Put(Item : in Part_Type) is
   begin
      Put("Part nummer ");
      Put(item.Part_Nr,1);
      Put(" har koordinaterna:");
      New_Line;
      Put(item.Coordinates);
      -- TESTKOD FÖR FIND ALL POSSIBLE POSITIONS
  --    Put("Antal möjliga positioner i figuren: ");
    --  Put(Item.Number_Of_Possible_Positions,1 );
     -- New_Line;
   end put;

   function Get_Pos_Array(Part : in Part_Type) return Position_Array is
   begin
      return Part.Part_Pos;
   end Get_Pos_Array;

   function Expand_Coordinate_List(Partial_Figure : in Coordinate_List.List_Pointer;
                                   Coords : in Coordinate_List.List_Pointer)
                                  return Coordinate_List.List_Pointer is
      Output_Coordinate_List : Coordinate_List.List_Pointer;
      Counter : Integer := 1;
      New_Coordinate : Coordinate_Type;
   begin
      for I in 1..Coordinate_List.Length(Partial_Figure) loop
         New_Coordinate.Number := Counter;
         New_Coordinate.Coordinates := Coordinate_List.Find(Partial_Figure,I).Coordinates;
         Coordinate_List.Insert(Output_Coordinate_List, New_Coordinate);
         Counter := Counter + 1;
      end loop;
      for J in 1..Coordinate_List.Length(Coords) loop

         New_Coordinate.Number := Counter;
         New_Coordinate.Coordinates := Coordinate_List.Find(coords,J).Coordinates;
        -- Put("Sätter in koordinat: ");
        -- Put(New_Coordinate.Coordinates(1),1);
        -- Put(",");
        -- Put(New_Coordinate.Coordinates(2),1);
        -- Put(",");
        -- Put(New_Coordinate.Coordinates(3),1);
         Coordinate_List.Insert(Output_Coordinate_List, New_Coordinate);
         Counter := Counter + 1;
      end loop;
      return Output_Coordinate_List;

   end Expand_Coordinate_List;

end Parts;

